package com.learn.demo.config;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.List;
import java.util.Map;

public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        Map<String, List<String>> map = request.getParameterMap();
        List<String> usernameList = map.get("username");
        if (usernameList != null && !usernameList.isEmpty()) {
            String username = usernameList.get(0); // 获取第一个用户名值
            System.out.println("用户名: " + username);
            sec.getUserProperties().put("username", username); // 将用户名存储在用户属性中
        }
    }
}
